/*
 * Copyright 2011 es-planning Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package jp.arctos.ursus.extension.net;

import jp.arctos.ursus.thread.RealtimeThreadParameters;

/**
 * Class that handles configuration.
 * 
 */
public class Config implements SessionConfig {

    /** Real-time thread parameters. */
    RealtimeThreadParameters realtimeThreadParameters = null;

    /** SO_RCVBUF Default socket option. */
    public static final int DEFAULT_RECEIVE_BUFFER_SIZE = 1024;

    /** SO_RCVBUF Size to configure for socket option. */
    int receiveBufferSize = DEFAULT_RECEIVE_BUFFER_SIZE;

    /** SO_REUSEADDR Socket option. Default: true */
    boolean reuseAddress = true;

    /** Default send request queue size. */
    public static final int DEFAULT_SEND_QUEUE_SIZE = 10;

    /** Send request queue size. */
    int sendQueueSize = DEFAULT_SEND_QUEUE_SIZE;

    /** Default size for data storage buffer. */
    public static final int DEFAULT_RECEIVED_CONTEXT_BUFFER_SIZE = 1024;

    /** Size for data storage buffer. */
    int receivedContextBufferSize = DEFAULT_RECEIVED_CONTEXT_BUFFER_SIZE;

    /**
     * Get real-time thread parameters.
     * 
     * @return Real-time thread parameters
     */
    public RealtimeThreadParameters getRealtimeThreadParameters() {
        return realtimeThreadParameters;
    }

    /**
     * Configure real-time thread parameters.
     * 
     * @param realtimeThreadParameters Real-time thread parameters
     */
    public void setRealtimeThreadParameters(RealtimeThreadParameters realtimeThreadParameters) {
        this.realtimeThreadParameters = realtimeThreadParameters;
    }

    /**
     * SO_RCVBUF Get size for socket option.
     * 
     * @return SO_RCVBUF Size for socket option
     */
    public int getReceiveBufferSize() {
        return receiveBufferSize;
    }

    /**
     * SO_RCVBUF Configure size for socket option.
     * 
     * @param receiveBufferSize SO_RCVBUF Size for socket option
     */
    public void setReceiveBufferSize(int receiveBufferSize) {
        this.receiveBufferSize = receiveBufferSize;
    }

    /**
     * SO_REUSEADDR Get flag for socket option.
     * 
     * @return SO_REUSEADDR Flag for socket option
     */
    public boolean getReuseAddress() {
        return reuseAddress;
    }

    /**
     * SO_REUSEADDR Configure flag for socket option.
     * 
     * @param reuseAddress SO_REUSEADDR Flag for socket option
     */
    public void setReuseAddress(boolean reuseAddress) {
        this.reuseAddress = reuseAddress;
    }

    /**
     * Get size for send request queue.
     * 
     * @return Size for send queue
     */
    public int getSendQueueSize() {
        return sendQueueSize;
    }

    /**
     * Configure size for send request queue.
     * When receiving a data send request, temporarily store the request <br>
     * in a fixed-length buffer until the channel can be written to.
     * 
     * @param sendQueueSize
     */
    public void setSendQueueSize(int sendQueueSize) {
        this.sendQueueSize = sendQueueSize;
    }

    /**
     * Get size of received data storage buffer.
     * 
     * @return Size of received data storage buffer
     */
    public int getReceivedContextBufferSize() {
        return receivedContextBufferSize;
    }

    /**
     * Configure size of received data storage buffer.
     * The size of buffers for reading data received from a channel will be fixed size.
     * 
     * @param receivedContextBufferSize Size of received data storage buffer
     */
    public void setReceivedContextBufferSize(int receivedContextBufferSize) {
        this.receivedContextBufferSize = receivedContextBufferSize;
    }
}
